﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace WindowsSignInPage
{
    public class Logger
    {
        static readonly string LogPath;
        static Logger()
        {
            LogPath = HttpContext.Current.Server.MapPath("~/")+"splog.txt";
           
        }
        public static void Info(string message)
        {
            Write(string.Format("[Info] [{0}] \t {1}", DateTime.Now, message));
        }

        public static void Error(string message, Exception ex)
        {
            Write(string.Format("[Error] [{0}] \t {1}", DateTime.Now, message));
            Write(string.Format("\t{0}", ex.Message));
            Write(string.Format("\t{0}", ex.StackTrace));
        }

        private static void Write(string text)
        {
            if (!File.Exists(LogPath))
                return;
            using (StreamWriter sw = new StreamWriter(LogPath,true))
            {
                sw.Write(text);
                sw.Write(Environment.NewLine);
                sw.AutoFlush = true;
            }
        }
    }
}